#!/bin/bash

VER=`cat ../core/package.json | grep version`
VER=${VER#*:*\"}
VER=${VER%\.*}

OLDVER=`cat ./ver`

if [[ $VER == $OLDVER ]]
then
    echo "====skip===============$VER"
    exit
fi

echo "===================eplc : $OLDVER => $VER"

ETAG=${VER//\./dot}

echo $VER > ./ver

rm -rf ./build
cp -r ../core/build .

cat > ./serve.json <<EOF
{
    "headers": [
        {
            "source": "**",
            "headers": [{
                    "key": "ETag",
                    "value": "$ETAG"
                },{
                    "key": "Cache-Control",
                    "value": "no-cache"
                }]
        }
    ]
}
EOF

docker build -t eplc:$VER .
